<!DOCTYPE html>
<html lang="zh_cn">
<head>
          <title>来玩魔王的咚</title>
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta charset="utf-8" />
        <!-- twitter card metadata -->
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="/images/mowang.png">
<meta name="twitter:site" content="">
<meta name="twitter:title" content="Python site 模块">
<meta name="twitter:description" content="<p>pth文件追加sys.path路径；sitecustomize，usercustomize默认启动执行命令，改变python shell的提示符；普通用户pip安装模块；python环境变量</p>">
        <!-- OG Tags -->
<meta property="og:url" content="/python-moudle-site.html"/>
<meta property="og:title" content="来玩魔王的咚 | Python site 模块" />
<meta property="og:description" content="<p>pth文件追加sys.path路径；sitecustomize，usercustomize默认启动执行命令，改变python shell的提示符；普通用户pip安装模块；python环境变量</p>" />
        <!-- favicon -->
        <link rel="icon" type="image/png" href="/images/mowang.png">
        <!-- moment.js for date formatting -->
        <script src="/theme/js/moment.js"></script>
        <!-- css -->
        <link rel="stylesheet" type="text/css" href="/theme/css/main.css" />
        <!-- 左边的menu，如果页面高度不够，就跟着滚动，否则文章分类显示不全 -->
        <link rel="stylesheet" type="text/css" href="/theme/css/mycss/menu.css" />
		<script>
			
                /*! grunt-grunticon Stylesheet Loader - v2.1.2 | https://github.com/filamentgroup/grunticon | (c) 2015 Scott Jehl, Filament Group, Inc. | MIT license. */
    
    (function(e){function t(t,n,r,o){"use strict";function a(){for(var e,n=0;u.length>n;n++)u[n].href&&u[n].href.indexOf(t)>-1&&(e=!0);e?i.media=r||"all":setTimeout(a)}var i=e.document.createElement("link"),l=n||e.document.getElementsByTagName("script")[0],u=e.document.styleSheets;return i.rel="stylesheet",i.href=t,i.media="only x",i.onload=o||null,l.parentNode.insertBefore(i,l),a(),i}var n=function(r,o){"use strict";if(r&&3===r.length){var a=e.navigator,i=e.Image,l=!(!document.createElementNS||!document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect||!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image","1.1")||e.opera&&-1===a.userAgent.indexOf("Chrome")||-1!==a.userAgent.indexOf("Series40")),u=new i;u.onerror=function(){n.method="png",n.href=r[2],t(r[2])},u.onload=function(){var e=1===u.width&&1===u.height,a=r[e&&l?0:e?1:2];n.method=e&&l?"svg":e?"datapng":"png",n.href=a,t(a,null,null,o)},u.src="",document.documentElement.className+=" grunticon"}};n.loadCSS=t,e.grunticon=n})(this);(function(e,t){"use strict";var n=t.document,r="grunticon:",o=function(e){if(n.attachEvent?"complete"===n.readyState:"loading"!==n.readyState)e();else{var t=!1;n.addEventListener("readystatechange",function(){t||(t=!0,e())},!1)}},a=function(e){return t.document.querySelector('link[href$="'+e+'"]')},c=function(e){var t,n,o,a,c,i,u={};if(t=e.sheet,!t)return u;n=t.cssRules?t.cssRules:t.rules;for(var l=0;n.length>l;l++)o=n[l].cssText,a=r+n[l].selectorText,c=o.split(");")[0].match(/US\-ASCII\,([^"']+)/),c&&c[1]&&(i=decodeURIComponent(c[1]),u[a]=i);return u},i=function(e){var t,o,a;o="data-grunticon-embed";for(var c in e)if(a=c.slice(r.length),t=n.querySelectorAll(a+"["+o+"]"),t.length)for(var i=0;t.length>i;i++)t[i].innerHTML=e[c],t[i].style.backgroundImage="none",t[i].removeAttribute(o);return t},u=function(t){"svg"===e.method&&o(function(){i(c(a(e.href))),"function"==typeof t&&t()})};e.embedIcons=i,e.getCSS=a,e.getIcons=c,e.ready=o,e.svgLoadedCallback=u,e.embedSVG=u})(grunticon,this);
                
                grunticon(["/theme/css/icons.data.svg.css", "/theme/css/icons.data.png.css", "/theme/css/icons.fallback.css"]);
            </script>
        <noscript><link href="/theme/css/icons.fallback.css" rel="stylesheet"></noscript>
        <!-- menu toggle javascript -->
        <script type="text/javascript">
            document.addEventListener("DOMContentLoaded", initMenu);
            
            function initMenu(){
                var menu = document.getElementById("menu");
                var menulink = document.getElementById("menu-link");
                menulink.addEventListener("click", function toggleMenu(){
                        window.event.preventDefault();
                        menulink.classList.toggle('active');
                        menu.classList.toggle('active');              
                    });
            };
        </script>
        <!-- 不蒜子 -->
        <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>

    <meta name="description" content="<p>pth文件追加sys.path路径；sitecustomize，usercustomize默认启动执行命令，改变python shell的提示符；普通用户pip安装模块；python环境变量</p>" />

    <meta name="tags" content="python模块" />
  <!-- 替换部分base的样式，看文章时，要再宽一点，右边有很多空间可以撑开 -->
  <link rel="stylesheet" type="text/css" href="/theme/css/mycss/article.css" />

</head>
<body>
    <div role="banner" id="masthead">
        <header>
            <a href="/"><img src="/images/mowang.png" alt="McManus Logo"></a>
                <h1>来玩魔王的咚@骑士救兵</h1>
            <a href="#menu" id="menu-link">more stuff</a>
            <nav id="menu">
                <ul>
                        <li><a href="/tags">tags</a></li>
                            <li><a href="/category/cloud.html">Cloud</a></li>
                            <li><a href="/category/docker.html">Docker</a></li>
                            <li><a href="/category/go.html">Go</a></li>
                            <li><a href="/category/linux.html">Linux</a></li>
                            <li class="active"><a href="/category/python.html">Python</a></li>
                            <li><a href="/category/xue-xi-bi-ji.html">学习笔记</a></li>
                            <li><a href="/category/yun-wei-zi-dong-hua.html">运维自动化</a></li>
                </ul>
            </nav>
        </header>
    </div>
        <div class="page" role="main">
  <div class="article" role="article">
    <article>
        <footer>
            <a name="top"></a>
            <p>
              <time datetime=" 2020-09-30 14:40:00+08:00">
                <script>document.write(moment('2020-09-30 14:40:00+08:00').format('LL'));</script>
              </time>
              ~
              <time datetime=" 2020-09-30 14:40:00+08:00">
                <script>document.write(moment('2020-10-30 10:30:00+08:00').format('LL'));</script>
              </time>
            </p>
        </footer>
        <header>
          <h2>
            Python site 模块
          </h2>
        </header>
      <div class="content">
         <div class="toc">
<ul>
<li><a href="#pth-wen-jian">pth 文件</a></li>
<li><a href="#sitecustomize">sitecustomize</a><ul>
<li><a href="#gai-bian-python-shell-de-ti-shi-fu">改变python shell的提示符</a></li>
</ul>
</li>
<li><a href="#pu-tong-yong-hu-pip-an-zhuang-mo-kuai">普通用户pip安装模块</a><ul>
<li><a href="#she-zhi-ming-ling-bie-ming-bu-tui-jian">设置命令别名（不推荐）</a></li>
<li><a href="#jin-yong-enable_user_site">禁用ENABLE_USER_SITE</a></li>
</ul>
</li>
<li><a href="#python-huan-jing-bian-liang">python 环境变量</a></li>
</ul>
</div>
<p>标准库：<a href="https://docs.python.org/zh-cn/3/library/site.html">https://docs.python.org/zh-cn/3/library/site.html</a><br>
site 模块，指定域的配置钩子。<br>
Python文档：<a href="https://docs.python.org/zh-cn/3/using/cmdline.html">https://docs.python.org/zh-cn/3/using/cmdline.html</a><br>
命令行与环境变量。  </p>
<h3 id="pth-wen-jian"><a class="toclink" href="#pth-wen-jian">pth 文件</a></h3>
<p>可以在python启动时，添加模块搜索路径，也就是sys.path。只需要创建任意文件名的name.pth(name代指某个文件名)文件，并且放在某个搜索路径的目录中。<br>
文件的内容是一行写一个路径，可以是相对路径，也可以是绝对路径。不存在的项目不会添加到sys.path，也不会重复添加一样的路径。可以放心使用。<br>
另外这个文件中也可以写简单的代码，会被执行。以import+空格开始的行会被执行。这里限制代码只能写一行，是有意这么做的，不鼓励在这里写复杂的逻辑，在别处留了钩子。设置可执行代码的预期目的只是为了导入模块，比如加载第三方钩子。  </p>
<p>文件尽量放在site-packages（Ubuntu里是dist-packages）目录中，这个是最原始的查找路径。可以通过下面的方法确定：</p>
<div class="highlight"><pre><span></span><code><span class="o">&gt;&gt;&gt;</span> <span class="kn">import</span> <span class="nn">site</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">site</span><span class="o">.</span><span class="n">getusersitepackages</span><span class="p">()</span>
<span class="s1">&#39;/home/steed/.local/lib/python3.8/site-packages&#39;</span>
<span class="o">&gt;&gt;&gt;</span> <span class="n">site</span><span class="o">.</span><span class="n">getsitepackages</span><span class="p">()</span>
<span class="p">[</span><span class="s1">&#39;/usr/local/lib/python3.8/dist-packages&#39;</span><span class="p">,</span> <span class="s1">&#39;/usr/lib/python3/dist-packages&#39;</span><span class="p">,</span> <span class="s1">&#39;/usr/lib/python3.8/dist-packages&#39;</span><span class="p">]</span>
<span class="o">&gt;&gt;&gt;</span>
</code></pre></div>

<p>普通用户如果没有系统权限，是可以在自己家目录下创建指定的目录然后放置文件的。  </p>
<h3 id="sitecustomize"><a class="toclink" href="#sitecustomize">sitecustomize</a></h3>
<p>在上面的路径导入后，会尝试导入sitecustomize模块，也就是执行sitecustomize.py文件的代码，这个文件放置在sys.path的目录下。默认是不存在这个文件的，可以创建并写入代码，就会在python启动时执行。  </p>
<p>之后还会尝试导入usercustomize模块，逻辑同上面是一样的，只所以设置两个钩子，为了面向管理员和普通用户：</p>
<ul>
<li>先加载sitecustomize，管理员可以在系统目录中创建文件</li>
<li>ENABLE_USER_SITE 变量默认是true，可以在sitecustomize里关闭，就不会导入usercustomize</li>
<li>如果用-s参数启动python，也不会导入usercustomize</li>
<li>普通用户可以在用户的site-packages文件夹中创建usercustomize.py文件</li>
<li>因为是模块导入的方式，文件可以放在多个路径中，但是只有最先找到的文件才有效，查找顺序为sys.path</li>
</ul>
<p>用python启动site模块，输出如下：</p>
<div class="highlight"><pre><span></span><code>$ python -m site
sys.path <span class="o">=</span> <span class="o">[</span>
    <span class="s1">&#39;/home/steed&#39;</span>,
    <span class="s1">&#39;/usr/lib/python38.zip&#39;</span>,
    <span class="s1">&#39;/usr/lib/python3.8&#39;</span>,
    <span class="s1">&#39;/usr/lib/python3.8/lib-dynload&#39;</span>,
    <span class="s1">&#39;/home/steed/.local/lib/python3.8/site-packages&#39;</span>,
    <span class="s1">&#39;/usr/local/lib/python3.8/dist-packages&#39;</span>,
    <span class="s1">&#39;/usr/lib/python3/dist-packages&#39;</span>,
<span class="o">]</span>
USER_BASE: <span class="s1">&#39;/home/steed/.local&#39;</span> <span class="o">(</span>exists<span class="o">)</span>
USER_SITE: <span class="s1">&#39;/home/steed/.local/lib/python3.8/site-packages&#39;</span> <span class="o">(</span>exists<span class="o">)</span>
ENABLE_USER_SITE: True
$ 
</code></pre></div>

<p>sys.path 的第一个路径为当前路径，并不是优先查找模块的路径，有可能是后插入的。<br>
为安全起见，先查找系统中是否已经存在sitecustomize.py和usercustomize.py文件，有的话备份编辑，没有的话再创建新的。保证两个文件各只有一个，多了也只认一个。<br>
上面几个全大写的都是全局变量，需要的话在sitecustomize.py中修改掉，比如把ENABLE_USER_SITE设置为False。  </p>
<p>用途：既然可以执行任意代码，那么可以调用print，打印一段文本，或者打打图形出来。虽然没什么大用。  </p>
<h4 id="gai-bian-python-shell-de-ti-shi-fu"><a class="toclink" href="#gai-bian-python-shell-de-ti-shi-fu">改变python shell的提示符</a></h4>
<p>默认的提示符是<code>&gt;&gt;&gt;</code>，这个可以通过改变sys.ps1的值来改变，把下面的代码放到usercustomize.py中试试：</p>
<div class="highlight"><pre><span></span><code><span class="kn">import</span> <span class="nn">sys</span>
<span class="n">sys</span><span class="o">.</span><span class="n">ps1</span> <span class="o">=</span> <span class="s1">&#39;@@@ &#39;</span>
</code></pre></div>

<h3 id="pu-tong-yong-hu-pip-an-zhuang-mo-kuai"><a class="toclink" href="#pu-tong-yong-hu-pip-an-zhuang-mo-kuai">普通用户pip安装模块</a></h3>
<p>显然pip命令也是用python写的，都是要启动python的，默认都会加载site模块。而模块安装的路径就是由site中设置的路径决定的。  </p>
<p>系统管理员安装模块是安装到系统目录的。而普通用户可能会安装到用户家目录，因为没有系统目录的写权限。这时候可以加上sudo执行。<br>
普通用户，不加sudo执行的时候，在检查目录没有写权限后，会安装到用户目录下。这个路径是由上面的USER_SITE变量决定的。下面是普通用户执行pip安装时的输出：</p>
<div class="highlight"><pre><span></span><code>$ pip install numpy
Defaulting to user installation because normal site-packages is not writeable
Looking <span class="k">in</span> indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting numpy
  Using cached https://mirrors.aliyun.com/pypi/packages/0e/f7/a7d7e0de99a7b43bd95aaddcf29e65b5a185ca389dd1329a53cc986edc38/numpy-1.19.3-cp36-cp36m-manylinux2010_x86_64.whl <span class="o">(</span><span class="m">14</span>.9 MB<span class="o">)</span>
Installing collected packages: numpy
Successfully installed numpy-1.19.3
$ 
</code></pre></div>

<p>第一行会输出一行不太明显的提示，说明了没有系统目录写权限，安装到了用户目录。  </p>
<p>使用sudo执行pip安装的时候，不只是给命令赋予了root权限，同时这个python命令的调用账号也变成了root。这里会有以下的问题：</p>
<ol>
<li>如果用户家目录设置了pypi源，此时会去查找root的家目录。没有就用默认源</li>
<li>如果忘记加sudo，就会安装到当前用户的家目录里，不符合预期也不会报错或警告</li>
</ol>
<h4 id="she-zhi-ming-ling-bie-ming-bu-tui-jian"><a class="toclink" href="#she-zhi-ming-ling-bie-ming-bu-tui-jian">设置命令别名（不推荐）</a></h4>
<p>设置pypi源的时候，为root账号也添加一份设置。<br>
为pip命令加一个别名<code>alias pip='sudo pip'</code>，可以避免忘记加sudo。这么做应该就可以了。  </p>
<h5 id="bu-tui-jian-de-yuan-yin"><a class="toclink" href="#bu-tui-jian-de-yuan-yin">不推荐的原因</a></h5>
<p>只所以不推荐，因为这个做法无法适应使用python虚拟环境（venv）。<br>
启用了虚拟环境后，会将虚拟环境的bin目录添加到$PATH环境变量的最前面。这样在执行pip命令时，会首先找到虚拟环境中的pip命令执行，从而将模块安装到虚拟环境的目录中。<br>
而sudo有自己的$PATH的设置，建议用visudo命令查看配置：</p>
<div class="highlight"><pre><span></span><code><span class="c1"># Ubuntu</span>
Defaults        <span class="nv">secure_path</span><span class="o">=</span><span class="s2">&quot;/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin&quot;</span>
<span class="c1"># Centos7</span>
Defaults    <span class="nv">secure_path</span> <span class="o">=</span> /sbin:/bin:/usr/sbin:/usr/bin
</code></pre></div>

<p>由于这个原因，即使启用了虚拟环境，但是调用<code>sudo pip</code>命令，执行的还是原来系统中的pip。这样模块还是安装到原来的路径而不是期望的虚拟环境的目录中。  </p>
<h4 id="jin-yong-enable_user_site"><a class="toclink" href="#jin-yong-enable_user_site">禁用ENABLE_USER_SITE</a></h4>
<p>再看一下site模块的输出：</p>
<div class="highlight"><pre><span></span><code>$ python3 -m site
sys.path <span class="o">=</span> <span class="o">[</span>
    <span class="s1">&#39;/home/steed&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python36.zip&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6/lib-dynload&#39;</span>,
    <span class="s1">&#39;/home/steed/.local/lib/python3.6/site-packages&#39;</span>,
    <span class="s1">&#39;/usr/local/lib64/python3.6/site-packages&#39;</span>,
    <span class="s1">&#39;/usr/local/lib/python3.6/site-packages&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6/site-packages&#39;</span>,
    <span class="s1">&#39;/usr/lib/python3.6/site-packages&#39;</span>,
<span class="o">]</span>
USER_BASE: <span class="s1">&#39;/home/steed/.local&#39;</span> <span class="o">(</span>exists<span class="o">)</span>
USER_SITE: <span class="s1">&#39;/home/steed/.local/lib/python3.6/site-packages&#39;</span> <span class="o">(</span>exists<span class="o">)</span>
ENABLE_USER_SITE: True
$ 
</code></pre></div>

<p>这次注意最后一个变量ENABLE_USER_SITE，只要禁用掉，就不会使用USER_BASE和USER_SITE的路径。这样既不会把模块安装到目录中，也不会从目录中查找模块。  </p>
<p>禁用ENABLE_USER_SITE有以下方法:</p>
<ol>
<li>在sitecustomize.py中把USER_SITE设置为False</li>
<li>使用-s参数执行python命令</li>
<li>设置环境变量PYTHONNOUSERSITE，对值没有任何要求，只要设置了就行</li>
</ol>
<p>设置环境变量最方便，验证效果：</p>
<div class="highlight"><pre><span></span><code>$ python3 -s -m site
sys.path <span class="o">=</span> <span class="o">[</span>
    <span class="s1">&#39;/home/steed&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python36.zip&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6/lib-dynload&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6/site-packages&#39;</span>,
    <span class="s1">&#39;/usr/lib/python3.6/site-packages&#39;</span>,
<span class="o">]</span>
USER_BASE: <span class="s1">&#39;/home/steed/.local&#39;</span> <span class="o">(</span>exists<span class="o">)</span>
USER_SITE: <span class="s1">&#39;/home/steed/.local/lib/python3.6/site-packages&#39;</span> <span class="o">(</span>exists<span class="o">)</span>
ENABLE_USER_SITE: False
$ <span class="nv">PYTHONNOUSERSITE</span><span class="o">=</span><span class="m">1</span> <span class="o">&amp;&amp;</span> python3 -m site
sys.path <span class="o">=</span> <span class="o">[</span>
    <span class="s1">&#39;/home/steed&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python36.zip&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6/lib-dynload&#39;</span>,
    <span class="s1">&#39;/usr/lib64/python3.6/site-packages&#39;</span>,
    <span class="s1">&#39;/usr/lib/python3.6/site-packages&#39;</span>,
<span class="o">]</span>
USER_BASE: <span class="s1">&#39;/home/steed/.local&#39;</span> <span class="o">(</span>exists<span class="o">)</span>
USER_SITE: <span class="s1">&#39;/home/steed/.local/lib/python3.6/site-packages&#39;</span> <span class="o">(</span>exists<span class="o">)</span>
ENABLE_USER_SITE: False
$ 
</code></pre></div>

<p>这里只是临时调试，真正使用时，需要将环境变量加到配置文件中。  </p>
<p>这样再执行pip安装模块时，如果没有系统目录写权限就会报错，而不会选择用户目录安装：</p>
<div class="highlight"><pre><span></span><code>$ <span class="nv">PYTHONNOUSERSITE</span><span class="o">=</span><span class="m">0</span> <span class="o">&amp;&amp;</span> pip install numpy
Traceback <span class="o">(</span>most recent call last<span class="o">)</span>:
  File <span class="s2">&quot;/usr/local/bin/pip&quot;</span>, line <span class="m">7</span>, <span class="k">in</span> &lt;module&gt;
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named <span class="s1">&#39;pip._internal&#39;</span>
$ <span class="nv">PYTHONNOUSERSITE</span><span class="o">=</span> <span class="o">&amp;&amp;</span> pip install numpy
Defaulting to user installation because normal site-packages is not writeable
Looking <span class="k">in</span> indexes: https://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: numpy <span class="k">in</span> ./.local/lib/python3.6/site-packages <span class="o">(</span><span class="m">1</span>.19.3<span class="o">)</span>
$ 
</code></pre></div>

<p>第一次设置了环境变量，pip报错了。忘了加sudo直接报错，符合预期，这样就可以再加上sudo执行一次。<br>
第二次环境变量没有设置，pip选择了用户目录。  </p>
<p>最后推荐用export命令将环境变量添加到.bashrc文件中：</p>
<div class="highlight"><pre><span></span><code><span class="c1"># 用于非交互式no-login shell</span>
$ <span class="nb">echo</span> <span class="s1">&#39;export PYTHONNOUSERSITE=1&#39;</span> &gt;&gt; ~/.bashrc
<span class="c1"># 用于交互式login shell，并且会再去调用.bashrc</span>
$ <span class="nb">echo</span> <span class="s1">&#39;export PYTHONNOUSERSITE=1&#39;</span> &gt;&gt; ~/.bash_profile
<span class="c1"># 在Debian中包括Ubuntu，代替.bash_profile</span>
$ <span class="nb">echo</span> <span class="s1">&#39;export PYTHONNOUSERSITE=1&#39;</span> &gt;&gt; ~/.profile
</code></pre></div>

<h3 id="python-huan-jing-bian-liang"><a class="toclink" href="#python-huan-jing-bian-liang">python 环境变量</a></h3>
<p>用环境变量的方式对python进行设置比较方便，比较常用的有下面几个：</p>
<ul>
<li>PYTHONPATH：增加模块文件默认搜索路径</li>
<li>PYTHONNOUSERSITE：如果设置了此变量，Python将不会把用户site-packages目录添加到sys.path</li>
</ul>
<p>更多的变量还是去查看官方文档，或者用<code>python3 --help</code>查看python命令有哪些选项，基本上应该都会有对应的环境变量来控制。  </p>
      </div>
      <div class="back-to-top">
        <a href="/">HOME</a>
        <a href="#top">TOP</a>
      </div>
    </article>
  </div>
<!-- end article -->
<!-- 页面往下滚动一段之后才会显示TOC -->
<script>
  window.onscroll = function() {
    var tocbox = document.getElementsByClassName('toc')[0];
    var osTop = document.documentElement.scrollTop || document.body.scrollTop;
    var osWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
    // console.log(osTop)
    if (osTop>300 && osWidth>865) {
      tocbox.style.display = "block"
    }
    if (osTop<300 || osWidth<865) {
      tocbox.style.display = "none"
    }
  }
</script>
                <footer>
                    <div class="icons">
                    </div>
                    <span id="busuanzi_container_page_pv" style="padding: 10px">本文阅读量<span id="busuanzi_value_page_pv"></span>次</span>
                    <span id="busuanzi_container_site_pv" style="padding: 10px">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>
                    <span id="busuanzi_container_site_uv" style="padding: 10px">本站总访客数<span id="busuanzi_value_site_uv"></span>人</span>
                    <p>© <script>document.write(moment().format('YYYY'));</script> 749B</p>
                </footer>
        </div>
</body>
</html>